#!/bin/bash

set -e
if [ ! -x "/sbin/parted" ]; then
    echo "This script requires /sbin/parted to run!" >&2
    exit 1
fi

DISKS="b c d e f g"
for i in ${DISKS}; do
    echo "Creating partitions on /dev/sd${i} ..."
    parted -a optimal --script /dev/sd${i} -- mktable gpt
    parted -s /dev/sd${i} mkpart primary 0% 20%
    parted -a optimal --script /dev/sd${i} -- mkpart entended xfs 21% 100%
    sleep 1
    #echo "Formatting /dev/sd${i}1 ..."
    mkfs.xfs -f /dev/sd${i}2 &
done

ceph-deploy disk zap dpaas46:sdb dpaas46:sdc dpaas46:sdd dpaas46:sde dpaas46:sdf dpaas46:sdg

ceph-deploy osd create dpaas46:/dev/sdb2:/dev/sdb1

for i in ${DISKS}; do
    echo "Creating partitions on /dev/sd${i} ..."
    parted -a optimal --script /dev/sd${i} -- mktable gpt
    
    parted -a optimal --script /dev/sd${i} -- mkpart primary xfs 0% 100%
      
    sleep 1
    #echo "Formatting /dev/sd${i}1 ..."
    mkfs.xfs -f /dev/sd${i}1 &
done

for i in ${DISKS}; do
    echo "Creating partitions on /dev/sd${i} ..."
    
    mkdir /data${i}
      
    sleep 1
    #echo "Formatting /dev/sd${i}1 ..."
    mount -t xfs /dev/sd${i}1 /data${i}
done

for i in ${DISKS}; do
    
    umount /data${i}
done

for i in ${DISKS}; do
    echo "Creating partitions on /dev/sd${i} ..."
    
    mkdir /data${i}/osd
      
    sleep 1
    #echo "Formatting /dev/sd${i}1 ..."
    chown -R  ceph:ceph /data${i}/osd
done

SSDS="c f"
for i in ${SSDS}; do
    parted -s /dev/sd${i} mklabel gpt
    parted -s /dev/sd${i} mkpart primary 0% 20%
    parted -s /dev/sd${i} mkpart primary 21% 40%
    parted -s /dev/sd${i} mkpart primary 41% 60%
    parted -s /dev/sd${i} mkpart primary 61% 80%
    parted -s /dev/sd${i} mkpart primary 81% 100%
done